﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using ESOL.Common.Entity;
using ESOL.Business.Prod;

namespace ESOL.WinUI.Manufacture
{
    public partial class frmMaintainWorkingOrderTechnicQuery : BaseForm.frmBaseDialogyQueryForm
    {
        #region Variables
        public ProdProductTechnicEntity SelectedProdProductTechnic
        {
            get
            {
                if (_SelectedProdProductTechnic != null)
                    return _SelectedProdProductTechnic;
                else return null;
            }
        }
        private ProdPlanOrderItemEntity SelectedProdPlanOrderItem;
        private ProdProductTechnicEntity _SelectedProdProductTechnic;
        #endregion

        #region Constructor
        public frmMaintainWorkingOrderTechnicQuery()
        {
            InitializeComponent();
        }

        public frmMaintainWorkingOrderTechnicQuery(ProdPlanOrderItemEntity entity)
        {
            InitializeComponent();
            SelectedProdPlanOrderItem = entity;
        }
        #endregion

        #region Functions
        private void BindComobox()
        {
            UICommon.UICommonFunctions.BindGridComboboxByCommonItem(colStationType, "STT", false);
        }

        private void SetField()
        {
            if (SelectedProdPlanOrderItem != null)
            {
                txtOrderItem.Text = SelectedProdPlanOrderItem.OrderItemCode;
                txtOrderItem.Tag = SelectedProdPlanOrderItem;
            }
        }

        private void BingGridData()
        {
            if (SelectedProdPlanOrderItem == null)
                return;
            DataTable dt=ProdProductTechnicBs.GetDtItemFlowStationByItemID(SelectedProdPlanOrderItem.PlanOrderItemId);
            gvMain.DataSource = dt;
        }
        #endregion

        #region Events
        protected override void OnShown(EventArgs e)
        {
            base.OnShown(e);
            BindComobox();
            SetField();
            BingGridData();
        }

        protected override void Click_Query()
        {
            BingGridData();
        }

        private void gridView1_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
        {
            DataRow dr = gridView1.GetDataRow(e.RowHandle);
            _SelectedProdProductTechnic = new ProdProductTechnicEntity(dr);
        }

        private void gridView1_DoubleClick(object sender, EventArgs e)
        {
            if (_SelectedProdProductTechnic == null)
            {
                MessageBox.Show("请选择一道工序！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            this.DialogResult = DialogResult.OK;
        }

        protected override void Click_Confirm()
        {
            if (_SelectedProdProductTechnic == null)
            {
                MessageBox.Show("请选择一道工序！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            this.DialogResult = DialogResult.OK;
        }

        #endregion



    }
}
